import { defineSeed } from "@/seed-application/types";
import SetActions from "../components/SetActions.vue";
import feedback from "@/utils/feedback";
import SetDatas from "../components/SetDatas.vue";
import SetFields from "../components/SetFields.vue";
import { open } from "@/components/Popup";

export default defineSeed({
  name: 'role',
  label: '角色',
  icon: 'ep:plus',
  declares: ['id', 'name'],
  searches: ['name_like'],
  checkLogin: false,
  checkAction: false,
  actions: {
    page: {
      label: '角色列表',
      type: 'page'
    },
    lookup: {
      label: '查找角色',
      type: 'page',
      icon: 'ep:plus'
    },
    save: {
      label: '新增',
      type: 'save',
      layout: {
          cls: ['full'],
          style: {
            display: 'grid',
            gridTemplateColumns: '150px minmax(0, 1fr) 150px',
            gridTemplateRows: '150px minmax(0, 1fr) 150px',
            gridTemplateAreas: "'one two three' 'four five six' 'seven eight nine'"
          },
          children: [
            {
              cls: ['flex-center'],
              style: {gridArea: 'two'},
              content: '这个是布局新增测试页面'
            },
            {
              type: 'save',
              cls: ['border'],
              style: {gridArea: 'five'},
              componentProps: {actionName: '$actionName', seedName: '$seedName', microName: '$microName', refresh: '$refresh'}
            }
          ]
      },
      icon: 'ep:plus',
      declares: ['name']
    },
    update: {
      label: '编辑',
      type: 'update',
      layout: {
          cls: ['full'],
          style: {
            display: 'grid',
            gridTemplateColumns: '150px minmax(0, 1fr) 150px',
            gridTemplateRows: '150px minmax(0, 1fr) 150px',
            gridTemplateAreas: "'one two three' 'four five six' 'seven eight nine'"
          },
          children: [
            {
              cls: ['flex-center'],
              style: {gridArea: 'two'},
              content: '这个是布局编辑测试页面'
            },
            {
              type: 'update',
              cls: ['border'],
              style: {gridArea: 'five'},
              componentProps: {actionName: '$actionName', seedName: '$seedName', microName: '$microName', id: '$id', refresh: '$refresh'}
            }
          ]
      },
      icon: 'ep:edit'
    },
    actions: {
      label: '分配功能权限',
      onClick: (action, unit, row) => {
        if(row) {
          open({title: action.label, width: '25vw', unit}, SetActions, {action, id: row.id})
        } else {
          feedback.alertSelect()
        }
      }
    },
    datas: {
      label: '分配数据权限',
      onClick: (action, unit, row) => {
        if(row) {
          open({title: action.label, unit}, SetDatas, {action, id: row.id})
        } else {
          feedback.alertSelect()
        }
      }
    },
    fields: {
      label: '分配字段权限',
      onClick: (action, unit, row) => {
        if(row) {
          open({title: action.label, unit}, SetFields, {action, id: row.id})
        } else {
          feedback.alertSelect()
        }
      }
    },
    remove: {
      label: '删除',
      type: 'remove'
    }
  },
  columns: {
    id: {name: 'id', type: 'char', length: 20, required: true, label: 'ID'},
    name: {name: 'name', type: 'varchar', required: true, length: 64, label: '名称'},
    tenant_id: {name: 'tenant_id', type: 'char', length: 20, label: '所属租户'},
    created_at: {name: 'created_at', type: 'datetime', label: '创建时间'},
    updated_at: {name: 'updated_at', type: 'datetime', label: '更新时间'},
    deleted_at: {name: 'deleted_at', type: 'datetime', label: '删除时间'},
    version: {name: 'version', type: 'int', label: '版本号'}
  }
})